package com.cyp.livelog.web;

import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @date 2020/12/15 18:29
 * @description
 */
@WebServlet("/logout")
public class LogoutAction extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Enumeration em = req.getSession().getAttributeNames();
    while (em.hasMoreElements()) {
      req.getSession().removeAttribute(em.nextElement().toString());
    }
    resp.sendRedirect(req.getContextPath() + "/home");
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    this.doGet(req, resp);
  }
}
